﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataEntity;
using Model;
using System.Collections.ObjectModel;

namespace SWA_View
{
    public partial class Changshui : Form
    {
        int _ProjectID;
        public ChangShuiEntity Entity = null;
        public ObservableCollection<ExperimentCombinationEntity> result = new ObservableCollection<ExperimentCombinationEntity>();
        public Changshui(int ProjectID)
        {
            InitializeComponent();
            _ProjectID = ProjectID;
            Entity = new ChangShuiEntity() { ProjectID = ProjectID, ExperimentType = ExperimentType.敞水试验.ToString() };
        }


        private void btnCancel_Click(object sender, EventArgs e)
        {

            DialogResult rsltEnsure = MessageBox.Show("确定要退出吗？", "确认关闭", MessageBoxButtons.OKCancel);
            if (rsltEnsure == DialogResult.OK)
            {

                this.DialogResult = DialogResult.Cancel;
                //this.Close();
            }
            else
            {

            }
        }
        
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                GetData();
                CommonModel model = new CommonModel();
                model.Save<ChangShuiEntity>(Entity);
                result.Clear();
                ExperimentCombinationEntity ex = new ExperimentCombinationEntity() { ProjectID = _ProjectID, IsIng = "否", IsFinished = "否", DataCombination = Entity.Text, ExperimentType = ExperimentType.敞水试验.ToString(), CreateDate = DateTime.Now };
                result.Add(ex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void Changshui_Load(object sender, EventArgs e)
        {
            //ChangshuiTestData = DbAccess.GetChangshuiTest(((Main) Owner).PrjBrief.PrjNo);
            //txtJiangmoNo.Text = ChangshuiTestData.JiangmoNo.ToString();
            //txtLuojuBi.Text = ChangshuiTestData.LuojuRatio.ToString();
            //txtPanmianBi.Text = ChangshuiTestData.PanmianRatio.ToString();
            //txtZhijing.Text = ChangshuiTestData.Zhijing.ToString();
        }

        public void SetData(ChangShuiEntity e)
        {
            txtJiangmoNo.Text = e.JiangmoNo;
            txtZhijing.Text = e.Diameter + "";
            txtLuojuBi.Text = e.LuoJuRate;
            txtPanmianBi.Text = e.PanMianRate;
        }

        public ChangShuiEntity GetData()
        {
            Entity.JiangmoNo = txtJiangmoNo.Text;
            Entity.Diameter = float.Parse(txtZhijing.Text);
            Entity.LuoJuRate = txtLuojuBi.Text;
            Entity.PanMianRate = txtPanmianBi.Text;
            return Entity;
        }

        private void txtRealLength_TextChanged(object sender, EventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
            {
                try
                {
                    double.Parse(tb.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("只能输入数字");
                    tb.Focus();
                    tb.Text = "0";
                }
            }
        }
    }
}
